﻿using System;
using System.Web;
using System.Net;
using System.IO;
using System.Text;
namespace Common.Net
{
    public static class IP
    {
        /// <summary>
        /// 得到访问网站的用户的远端IP
        /// </summary>
        /// <returns></returns>
        public static string GetIP()
        {
            string IpAddress = (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null && HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != String.Empty) ? HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] : HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
            return IpAddress;
        }

        /// <summary>
        /// 得到本机在内网上的IP
        /// </summary>
        /// <returns></returns>
        public static string GetLocalIP()//注意与static 的区别
        {
            System.Net.IPAddress[] addressList = Dns.GetHostEntry(Dns.GetHostName()).AddressList;//获取本机内网IP
            return addressList[0].ToString();

        }

    }
}
